<template>
  <div class="admin-login-page">
    <!-- 高级背景效果 -->
    <div class="background-effects">
      <div class="gradient-orbs">
        <div class="orb orb-1"></div>
        <div class="orb orb-2"></div>
        <div class="orb orb-3"></div>
      </div>
      <div class="grid-pattern"></div>
    </div>

    <!-- 登录容器 -->
    <div class="login-container">
      <div class="login-card">
        <!-- 顶部区域 -->
        <div class="login-header">
          <div class="logo-container">
            <div class="logo-wrapper">
              <!-- 图标 -->
              <div class="logo-icon artistic-icon">
                <div class="icon-shape">
                  <div class="fitness-symbol">
                    <div class="weight-circle"></div>
                    <div class="energy-wave"></div>
                    <div class="motion-line"></div>
                  </div>
                </div>
              </div>
              <div class="logo-text">
                <h1>FitPro</h1>
                <span>ADMIN</span>
              </div>
            </div>
          </div>
          <div class="welcome-text">
            <h2>后台管理系统登录</h2>
            <p>请登录您的管理员账户</p>
          </div>
        </div>

        <!-- 登录表单 -->
        <form @submit.prevent="handleLogin" class="login-form">
          <div class="form-group">
            <div class="input-container">
              <div class="input-icon">
                <i class="fas fa-user-cog"></i>
              </div>
              <input
                  v-model="loginForm.username"
                  type="text"
                  class="form-input"
                  placeholder="管理员账号"
                  required
              />
              <div class="input-border"></div>
              <div class="input-highlight"></div>
            </div>
          </div>

          <div class="form-group">
            <div class="input-container">
              <div class="input-icon">
                <i class="fas fa-key"></i>
              </div>
              <input
                  v-model="loginForm.password"
                  type="password"
                  class="form-input"
                  placeholder="管理员密码"
                  required
              />
              <div class="input-border"></div>
              <div class="input-highlight"></div>
            </div>
          </div>

          <div class="form-options">
            <label class="checkbox-container">
              <input type="checkbox" v-model="rememberMe" />
              <span class="checkmark"></span>
              <span class="checkbox-label">记住登录状态</span>
            </label>
            <a href="#" class="forgot-link">忘记密码？</a>
          </div>

          <button type="submit" class="login-button" :class="{ 'loading': isLoading }">
            <span class="button-text" v-if="!isLoading">
              <i class="fas fa-sign-in-alt"></i>
              登录系统
            </span>
            <span class="button-loading" v-else>
              <i class="fas fa-spinner fa-spin"></i>
              登录中...
            </span>
            <div class="button-shine"></div>
          </button>
        </form>

        <!-- 错误信息 -->
        <div v-if="errorMessage" class="error-message">
          <div class="error-icon">
            <i class="fas fa-exclamation-triangle"></i>
          </div>
          <span>{{ errorMessage }}</span>
        </div>

        <!-- 底部信息 -->
        <div class="login-footer">
          <div class="security-info">
            <i class="fas fa-shield-check"></i>
            <span>安全认证 • 专业管理系统</span>
          </div>
          <button class="back-button" @click="goBackToHome">
            <i class="fas fa-arrow-left"></i>
            返回首页
          </button>
        </div>
      </div>
    </div>

    <!-- 版本信息 -->
    <div class="version-info">
      v2.1.0 • Professional Admin System  © 2025 集美健身 版权所有
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

export default {
  name: 'AdminLogin',
  setup() {
    const router = useRouter()
    const loginForm = ref({
      username: '',
      password: ''
    })
    const rememberMe = ref(false)
    const errorMessage = ref('')
    const isLoading = ref(false)

    const handleLogin = async () => {
      errorMessage.value = ''
      isLoading.value = true

      // 模拟网络延迟
      await new Promise(resolve => setTimeout(resolve, 800))

      try {
        // 本地验证逻辑
        if (!loginForm.value.username.trim() || !loginForm.value.password.trim()) {
          errorMessage.value = '请输入管理员账号和密码'
          return
        }

        if (loginForm.value.username === 'admin' && loginForm.value.password === 'admin') {
          // 登录成功
          const adminData = {
            username: 'admin',
            role: 'superadmin',
            loginTime: new Date().toISOString()
          }

          // 保存管理员信息
          localStorage.setItem('adminToken', 'admin-authenticated-token')
          localStorage.setItem('adminInfo', JSON.stringify(adminData))

          if (rememberMe.value) {
            localStorage.setItem('adminRemember', 'true')
          }

          // 显示成功消息
          errorMessage.value = ''

          // 跳转到后台仪表板
          setTimeout(() => {
            router.replace('/admin/dashboard')
          }, 500)
        } else {
          errorMessage.value = '账号或密码错误'
        }
      } catch (error) {
        errorMessage.value = '登录过程中发生错误，请稍后重试'
      } finally {
        isLoading.value = false
      }
    }

    const goBackToHome = () => {
      router.push('/')
    }

    return {
      loginForm,
      rememberMe,
      errorMessage,
      isLoading,
      handleLogin,
      goBackToHome
    }
  }
}
</script>

<style scoped>
/* 艺术感图标样式 */
.artistic-icon {
  width: 60px;
  height: 60px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-shape {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  animation: float-icon 3s ease-in-out infinite;
}

.fitness-symbol {
  width: 100%;
  height: 100%;
  position: relative;
}

/* 重量圆圈 */
.weight-circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 3px solid;
  border-color: #667eea;
  border-radius: 50%;
  background: conic-gradient(
      from 0deg,
      transparent 0deg 180deg,
      rgba(102, 126, 234, 0.3) 180deg 360deg
  );
  animation: rotate-circle 8s linear infinite;
}

.weight-circle::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  background: radial-gradient(circle, #764ba2 0%, #667eea 100%);
  border-radius: 50%;
  box-shadow: 0 0 15px rgba(118, 75, 162, 0.5);
}

/* 能量波纹 */
.energy-wave {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  border: 2px solid;
  border-color: rgba(102, 126, 234, 0.3);
  border-radius: 50%;
  animation: pulse-wave 2s ease-out infinite;
}

.energy-wave::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  border: 1px solid;
  border-color: rgba(118, 75, 162, 0.2);
  border-radius: 50%;
  animation: pulse-wave 2s ease-out infinite 0.5s;
}

/* 运动线条 */
.motion-line {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
}

.motion-line::before,
.motion-line::after {
  content: '';
  position: absolute;
  background: linear-gradient(90deg, transparent, #667eea, transparent);
  height: 2px;
  border-radius: 1px;
}

.motion-line::before {
  top: 10px;
  left: 0;
  width: 100%;
  transform: rotate(45deg);
  animation: shine-line 3s ease-in-out infinite;
}

.motion-line::after {
  bottom: 10px;
  left: 0;
  width: 100%;
  transform: rotate(-45deg);
  animation: shine-line 3s ease-in-out infinite 1.5s;
}

/* 动画定义 */
@keyframes float-icon {
  0%, 100% {
    transform: translateY(0px) rotate(0deg);
  }
  50% {
    transform: translateY(-5px) rotate(5deg);
  }
}

@keyframes rotate-circle {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

@keyframes pulse-wave {
  0% {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 0;
  }
}

@keyframes shine-line {
  0%, 100% {
    opacity: 0.3;
    background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.5), transparent);
  }
  50% {
    opacity: 1;
    background: linear-gradient(90deg, transparent, #667eea, transparent);
  }
}

.admin-login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* 背景效果 */
.background-effects {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.gradient-orbs {
  position: relative;
  width: 100%;
  height: 100%;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.2;
  animation: float 8s ease-in-out infinite;
}

.orb-1 {
  width: 400px;
  height: 400px;
  top: 5%;
  left: 5%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  animation-delay: 0s;
}

.orb-2 {
  width: 350px;
  height: 350px;
  top: 70%;
  right: 10%;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  animation-delay: 2s;
}

.orb-3 {
  width: 300px;
  height: 300px;
  bottom: 10%;
  left: 15%;
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  animation-delay: 4s;
}

.grid-pattern {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
      linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 60px 60px;
  opacity: 0.5;
}

@keyframes float {
  0%, 100% { transform: translateY(0px) scale(1); }
  50% { transform: translateY(-30px) scale(1.05); }
}

/* 登录容器 - 调整比例使其更宽更矮 */
.login-container {
  width: 100%;
  max-width: 520px;
  padding: 1.5rem;
  position: relative;
  z-index: 10;
}

.login-card {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(25px);
  border-radius: 20px;
  padding: 2.5rem 3rem;
  box-shadow:
      0 25px 50px rgba(0, 0, 0, 0.4),
      inset 0 1px 0 rgba(255, 255, 255, 0.1),
      0 0 0 1px rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
}

/* 顶部区域 */
.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.logo-container {
  margin-bottom: 1.5rem;
}

.logo-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 1rem 1.5rem;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.logo-text h1 {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
  line-height: 1.2;
}

.logo-text span {
  font-size: 0.75rem;
  color: #94a3b8;
  font-weight: 600;
  letter-spacing: 1px;
}

.welcome-text h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: #f8fafc;
  margin: 0 0 0.5rem 0;
}

.welcome-text p {
  color: #94a3b8;
  font-size: 0.95rem;
  margin: 0;
  font-weight: 400;
}

/* 表单样式 */
.login-form {
  margin-bottom: 1.5rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.input-container {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: #64748b;
  font-size: 1rem;
  z-index: 2;
  transition: color 0.3s ease;
}

.form-input {
  width: 100%;
  padding: 1.125rem 1rem 1.125rem 3rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  font-size: 1rem;
  color: #f8fafc;
  transition: all 0.3s ease;
  position: relative;
  z-index: 1;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.form-input::placeholder {
  color: #64748b;
}

.form-input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(102, 126, 234, 0.6);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.form-input:focus + .input-border {
  opacity: 1;
  transform: scaleX(1);
}

.form-input:focus ~ .input-highlight {
  opacity: 1;
  transform: scaleX(1);
}

.input-border {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, #667eea, #764ba2);
  opacity: 0;
  transform: scaleX(0);
  transition: all 0.3s ease;
  border-radius: 0 0 12px 12px;
  z-index: 2;
}

.input-highlight {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
  border-radius: 12px;
  opacity: 0;
  transform: scaleX(0);
  transition: all 0.3s ease;
  z-index: 0;
}

/* 表单选项 */
.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

.checkbox-container {
  display: flex;
  align-items: center;
  cursor: pointer;
  color: #cbd5e1;
  transition: color 0.3s ease;
}

.checkbox-container:hover {
  color: #f8fafc;
}

.checkbox-container input {
  display: none;
}

.checkmark {
  width: 18px;
  height: 18px;
  border: 2px solid #475569;
  border-radius: 4px;
  margin-right: 0.75rem;
  position: relative;
  transition: all 0.3s ease;
  background: rgba(255, 255, 255, 0.05);
}

.checkbox-container input:checked + .checkmark {
  background: #667eea;
  border-color: #667eea;
}

.checkbox-container input:checked + .checkmark::after {
  content: '✓';
  position: absolute;
  color: white;
  font-size: 0.8rem;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.checkbox-label {
  font-weight: 500;
}

.forgot-link {
  color: #94a3b8;
  text-decoration: none;
  transition: color 0.3s ease;
  font-weight: 500;
}

.forgot-link:hover {
  color: #667eea;
}

/* 登录按钮 */
.login-button {
  width: 100%;
  padding: 1.125rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}

.login-button:hover:not(.loading) {
  transform: translateY(-2px);
  box-shadow: 0 12px 30px rgba(102, 126, 234, 0.4);
}

.login-button:active {
  transform: translateY(0);
}

.login-button.loading {
  cursor: not-allowed;
  opacity: 0.8;
}

.button-text, .button-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  position: relative;
  z-index: 2;
}

.button-shine {
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s ease;
}

.login-button:hover .button-shine {
  left: 100%;
}

/* 错误信息 */
.error-message {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(220, 38, 38, 0.1);
  border: 1px solid rgba(220, 38, 38, 0.2);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  animation: shake 0.5s ease-in-out;
}

.error-icon {
  color: #dc2626;
  font-size: 0.9rem;
}

.error-message span {
  color: #ef4444;
  font-size: 0.85rem;
  font-weight: 500;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* 底部信息 */
.login-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.security-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #64748b;
  font-size: 0.8rem;
  font-weight: 500;
}

.security-info i {
  color: #10b981;
}

.back-button {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.back-button:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #f8fafc;
  border-color: rgba(255, 255, 255, 0.2);
}

/* 版本信息 */
.version-info {
  position: absolute;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  color: #475569;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .login-container {
    padding: 1rem;
    max-width: 450px;
  }

  .login-card {
    padding: 2rem 1.5rem;
  }

  .logo-wrapper {
    flex-direction: column;
    gap: 0.75rem;
    text-align: center;
  }

  .form-options {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
  }

  .forgot-link {
    align-self: flex-end;
  }

  .login-footer {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .login-card {
    padding: 1.5rem 1.25rem;
  }

  .logo-text h1 {
    font-size: 1.5rem;
  }

  .welcome-text h2 {
    font-size: 1.25rem;
  }
}
</style>